/*jslint newcap:true,browser: true, devel: true, bitwise: true, white: true, plusplus: true, forin:true, nomen:true */
/*global $:true, define:true */

/**
 * @module Test
 */

define(function() {
"use strict";

/** 
 * 
 * @class waitFor
 * @constructor
 */

function waitFor(startCallback) {
	this.StartCallback = startCallback;
	this.waiting = true;
	this.ret = null;
}

waitFor.prototype = {
	constructor: waitFor,
	by: function(timeout) {
		var context = this;
		window.setTimeout(function() {
			throw new Error('waitFor timeout');
			//context.waiting = false;
		},timeout);
		return this.wait();
	},
	
	wait: function() {
		this.StartCallback.call(this);
		
		//while(this.waiting) {
		//	console.log(this.waiting);
		//}
		return this.ret;
	}
	
};

return waitFor;


});
